/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * wavedec.c
 *
 * Code generation for function 'wavedec'
 *
 */

/* Include files */
#include "wavedec.h"
#include "emxutil.h"
#include "types.h"
#include "rt_nonfinite.h"
#include <string.h>

/* Function Definitions */
void wavedec(const double x[2000], emxArray_real_T *c, double l[7])
{
  static const double b[6] = {0.035226291882100656, -0.085441273882241486,
                              -0.13501102001039084, 0.45987750211933132,
                              0.80689150931333875,  0.33267055295095688};
  static const double b_b[6] = {-0.33267055295095688, 0.80689150931333875,
                                -0.45987750211933132, -0.13501102001039084,
                                0.085441273882241486, 0.035226291882100656};
  emxArray_real_T *z;
  double z_data[2005];
  double xv_data[2000];
  double b_xv_data[1002];
  double *b_z_data;
  double *c_data;
  int I_data[2010];
  int b_k;
  int i;
  int ib;
  int k;
  int xv_size;
  c_data = c->data;
  c->size[0] = 0;
  for (i = 0; i < 7; i++) {
    l[i] = 0.0;
  }
  xv_size = 2000;
  memcpy(&xv_data[0], &x[0], 2000U * sizeof(double));
  l[6] = 2000.0;
  emxInit_real_T(&z, 1);
  for (k = 0; k < 5; k++) {
    int I_size_idx_1_tmp;
    int lx;
    lx = xv_size - 1;
    I_size_idx_1_tmp = xv_size + 10;
    memset(&I_data[0], 0, (unsigned int)I_size_idx_1_tmp * sizeof(int));
    for (b_k = 0; b_k < 5; b_k++) {
      I_data[b_k] = 5 - b_k;
    }
    for (b_k = 0; b_k <= lx; b_k++) {
      I_data[b_k + 5] = b_k + 1;
    }
    for (b_k = 0; b_k < 5; b_k++) {
      I_data[(xv_size + b_k) + 5] = xv_size - b_k;
    }
    if (I_size_idx_1_tmp - 6 >= 0) {
      memset(&z_data[0], 0,
             (unsigned int)(I_size_idx_1_tmp - 5) * sizeof(double));
    }
    for (ib = 0; ib < 6; ib++) {
      for (i = 0; i <= I_size_idx_1_tmp - 6; i++) {
        z_data[i] += b[5 - ib] * xv_data[I_data[ib + i] - 1];
      }
    }
    b_k = (xv_size + 3) / 2;
    lx = b_k + 1;
    for (i = 0; i <= b_k; i++) {
      b_xv_data[i] = z_data[(i << 1) + 1];
    }
    if (I_size_idx_1_tmp - 6 >= 0) {
      memset(&z_data[0], 0,
             (unsigned int)(I_size_idx_1_tmp - 5) * sizeof(double));
    }
    for (ib = 0; ib < 6; ib++) {
      for (i = 0; i <= I_size_idx_1_tmp - 6; i++) {
        z_data[i] += b_b[5 - ib] * xv_data[I_data[ib + i] - 1];
      }
    }
    xv_size = b_k + 1;
    if (lx - 1 >= 0) {
      memcpy(&xv_data[0], &b_xv_data[0], (unsigned int)lx * sizeof(double));
    }
    i = z->size[0];
    z->size[0] = (b_k + c->size[0]) + 1;
    emxEnsureCapacity_real_T(z, i);
    b_z_data = z->data;
    for (i = 0; i <= b_k; i++) {
      b_z_data[i] = z_data[(i << 1) + 1];
    }
    lx = c->size[0];
    for (i = 0; i < lx; i++) {
      b_z_data[(i + b_k) + 1] = c_data[i];
    }
    i = c->size[0];
    c->size[0] = z->size[0];
    emxEnsureCapacity_real_T(c, i);
    c_data = c->data;
    lx = z->size[0];
    for (i = 0; i < lx; i++) {
      c_data[i] = b_z_data[i];
    }
    l[5 - k] = (double)b_k + 1.0;
  }
  i = z->size[0];
  z->size[0] = xv_size + c->size[0];
  emxEnsureCapacity_real_T(z, i);
  b_z_data = z->data;
  for (i = 0; i < xv_size; i++) {
    b_z_data[i] = xv_data[i];
  }
  b_k = c->size[0];
  for (i = 0; i < b_k; i++) {
    b_z_data[i + xv_size] = c_data[i];
  }
  i = c->size[0];
  c->size[0] = z->size[0];
  emxEnsureCapacity_real_T(c, i);
  c_data = c->data;
  b_k = z->size[0];
  for (i = 0; i < b_k; i++) {
    c_data[i] = b_z_data[i];
  }
  emxFree_real_T(&z);
  l[0] = xv_size;
}

/* End of code generation (wavedec.c) */
